package com.lfs.market.controller.front;

import cn.dev33.satoken.stp.SaTokenInfo;
import com.lfs.market.model.R;
import com.lfs.market.model.dto.UserLoginDto;
import com.lfs.market.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/public")
public class PublicController {
    @Autowired
    private UserService userService;

    /**
     * 登录
     *
     * @param request
     * @return
     */
    @PostMapping("/user/login")
    public R<SaTokenInfo> login(@RequestBody UserLoginDto request) {
        SaTokenInfo loginToken = userService.login(request);
        return R.ok(loginToken);
    }


    /**
     * 根据密码登录
     *
     * @param request
     * @return
     */
    @PostMapping("/user/login/pwd")
    public R<SaTokenInfo> loginPwd(@RequestBody UserLoginDto request) {
        SaTokenInfo loginToken = userService.loginPwd(request);
        return R.ok(loginToken);
    }

    /**
     * 注册
     *
     * @param request
     * @return
     */
    @PostMapping("/user/register")
    public R<SaTokenInfo> register(@RequestBody UserLoginDto request) {
        SaTokenInfo loginToken = userService.register(request);
        return R.ok(loginToken);
    }


    /**
     * 根据短信验证码登录
     *
     * @param phone
     * @return
     */
    @GetMapping("/getCheckCode")
    public R<String> getLoginCode(String phone) {
        userService.getLoginCode(phone);
        return R.ok();
    }
}
